package com.goldstone.dao;

import org.springframework.stereotype.Component;
import org.springside.modules.orm.hibernate.HibernateDao;

import com.goldstone.entity.Order;

@Component
public class OrderDao  extends HibernateDao<Order, String> {

	public void save(Order order) {
		if(order.getId() == null)
			order.setOrderNum(getMaxNum() + 1);
		super.save(order);
	}
	
	public Integer getMaxNum() {
		Object max = getSession().createQuery("select max(orderNum) from Order " ).uniqueResult();
		return max == null ? 0 : (Integer)max;
	}
}
